home *** CD-ROM | disk | FTP | other *** search
/ FishMarket 1.0 / FishMarket v1.0.iso / fishies / 526-550 / disk_547 / findname / findname.asm < prev    next >
Assembly Source File  |  1992-05-06  |  3KB  |  132 lines

  1.  
  2. *    FindName
  3. *    By Preben Nielsen
  4. *
  5. *HISTORY
  6. *          Made with Hisoft V2.12
  7. *
  8. *  V1.0   10-Sep-91: First attempt. Works of course.
  9.  
  10.  
  11.     OPT O+
  12.     OPT O1+            ; Tells when a branch could be optimised to short
  13.     OPT i+            ; Tells when '#' is probably missing
  14.  
  15.         incdir        "AsmInc:"
  16.         include        "P.i"
  17.         include        "relMacros.i"
  18.         include        "exec/execbase.i"
  19.         include        "exec/exec_lib.i"
  20.         include        "libraries/dosextens.i"
  21.  
  22. DB        EQUR        A4
  23.  
  24.  dcDeclare    A4
  25.  dcArea        ArgTable,10*4    ; Here ArgParse leaves some pointers
  26.  dcArea        ArgLine,100    ; Copy of the commandline
  27.  dcEnd
  28.  
  29. Start        dcAlloc
  30.         dcReset
  31.         lea        ArgLine(DB),A1
  32.         move.l        D0,D1
  33.         bra.S        2$
  34. 1$        move.b        (A0)+,(A1)+
  35. 2$        dbf        D1,1$
  36.         lea        ArgLine(DB),A0
  37.         lea        ArgTable(DB),A1
  38.         Call        ArgParse
  39.         cmp.w        #2,D0        ; Correct number of arguments ?
  40.         blt        ArgError
  41.         move.l        ArgTable(DB),A0
  42.         cmp.b        #'-',(A0)+
  43.         bne        ArgError
  44.         move.b        (A0),D0
  45.         cmp.b        #'d',D0        ; Device ?
  46.         beq.S        SearchDevice
  47.         cmp.b        #'l',D0        ; Library ?
  48.         beq.S        SearchLibrary
  49.         cmp.b        #'m',D0        ; Memory ?
  50.         beq.S        SearchMemory
  51.         cmp.b        #'p',D0        ; Port ?
  52.         beq.S        SearchPort
  53.         cmp.b        #'r',D0        ; Resource ?
  54.         beq.S        SearchResource
  55.         cmp.b        #'t',D0        ; Task ?
  56.         beq.S        SearchTask
  57.         bra.S        ArgError
  58.  
  59. SearchDevice    move.l        #DeviceList,D2    ; Device !
  60.         bra.S        SearchName
  61. SearchLibrary    move.l        #LibList,D2    ; Library !
  62.         bra.S        SearchName
  63. SearchMemory    move.l        #MemList,D2    ; Memory !
  64.         bra.S        SearchName
  65. SearchPort    move.l        #PortList,D2    ; Port !
  66.         bra.S        SearchName
  67. SearchResource    move.l        #ResourceList,D2; Resource !
  68.         bra.S        SearchName
  69. SearchTask    Prepare        Exec_Call    ; Task !
  70.         CallLib        Forbid
  71.         move.l        ArgTable+4(DB),A1
  72.         CallLib        FindTask
  73.         bra.S        CheckResult
  74. SearchName    Prepare        Exec_Call
  75.         CallLib        Forbid
  76.         lea        0(A6,D2.W),A0
  77.         move.l        ArgTable+4(DB),A1
  78.         CallLib        FindName
  79. CheckResult    move.l        D0,D2
  80.         CallLib        Permit
  81.         tst.l        D2
  82.         beq.S        NoLuck
  83. FoundIt        moveq        #RETURN_OK,D0
  84.         bra.S        LetsReturn
  85. NoLuck        moveq        #RETURN_WARN,D0
  86.         bra.S        LetsReturn
  87. ArgError    moveq        #RETURN_ERROR,D0
  88. LetsReturn    dcFree
  89.         rts
  90.  
  91.  
  92. *»»» Call:    A0 = String to parse
  93. *»»»        A1 = Table to put arg-pointers
  94. *»»»        D0 = Length of string to parse
  95. *»»» Return:    D0 = Number of arguments
  96. *»»»        Each argument in the string will be NULL-terminated
  97. ArgParse    Push        D1-D2/A0-A3
  98.         move.l        A1,A3
  99.         clr.b        -1(A0,D0)
  100.         moveq        #0,D1
  101. ArgLoop
  102. SpaceLoop    cmp.b        #' ',(A0)+
  103.         beq.S        SpaceLoop
  104.         move.b        -(A0),D0
  105.         beq.S        DoneParse
  106.         cmp.b        #'"',D0
  107.         beq.S        QuoteParse
  108. NormParse    move.l        A0,(A3)+
  109.         addq.l        #1,D1
  110.         moveq        #' ',D2
  111. 1$        move.b        (A0)+,D0
  112.         beq.S        DoneParse
  113.         cmp.b        D2,D0
  114.         bne.S        1$
  115.         bra.S        EndParse
  116. QuoteParse    addq.l        #1,A0
  117.         move.l        A0,(A3)+
  118.         addq.l        #1,D1
  119.         moveq        #'"',D2
  120. 1$        move.b        (A0)+,D0
  121.         beq.S        QuoteError
  122.         cmp.b        D2,D0
  123.         bne.S        1$
  124. EndParse    clr.b        -1(A0)
  125.         bra.S        ArgLoop
  126. QuoteError    moveq        #0,D1
  127. DoneParse    move.l        D1,D0
  128.         Pop        D1-D2/A0-A3
  129.         rts
  130.         END
  131.  
  132.